#include "addatatype.h"
#include <QDebug>

ADDataType::ADDataType():Success(false),
  media_id(-1), proj_id(-1)
{
    is_scene = false;
    name_is_sure = false;
}

ADDataType::ADDataType(const ADDataType &A){
    if(this != &A){
        Success = A.Success;
        media_id = A.media_id;
        proj_id = A.proj_id;

        media_audio_response = A.media_audio_response;
        media_cn = A.media_cn;
        media_attr_cn = A.media_attr_cn;
        media_name = A.media_name;
        attri = A.attri;
        pre_unit = A.pre_unit;
        value = A.value;
        value_cn = A.value_cn;
        value_type = A.value_type;
        unit = A.unit;
        m_through = A.m_through;
        m_range = A.m_range;

        floor = A.floor;
        area = A.area;

        name_is_sure = A.name_is_sure;
        is_scene = A.is_scene;

        sentence = A.sentence;
    }
}

ADDataType::ADDataType(QJsonObject &obj){
    media_id = -1;
    proj_id = -1;
    if( !(obj.contains("M_NameEN") && obj.contains("M_AttrEN") && obj.contains("M_AreaCN")) ){
        Success = false;
        is_scene = false;
        name_is_sure = false;
        return;
    }
    Success = true;
    attri = obj.value("M_AttrEN").toString();
    area = obj.value("M_AreaCN").toString();
    media_attr_cn = obj.value("M_AttrCN").toString();
    floor = obj.value("M_FloorCN").toString();
    media_cn = obj.value("M_NameCN").toString();
    name_is_sure = obj.value("M_NameEnsure").toString() == "1" ? true : false;
    pre_unit = obj.value("M_OperatorEN").toString();
    media_audio_response = obj.value("M_Response").toString();
    is_scene = obj.value("M_IsScene").toString() == "1" ? true : false;
    sentence = obj.value("M_SourceStr").toString();
    media_name = obj.value("M_NameEN").toString();
    unit = obj.value("M_Unit").toString();
    value = obj.value("M_ValueEN").toString();
    value_cn = obj.value("M_ValueCN").toString();
    value_type = obj.value("M_ValueType").toString();
    m_through = obj.value("M_Through").toString();
    m_range = obj.value("M_RangeEN").toString();
}

ADDataType::~ADDataType(){
    //请勿在此操作 args_ 参数   
}

bool ADDataType::operator ==(const ADDataType &A){
    if(this == &A) return true;
    else return(
        media_id == A.media_id &&
        proj_id == A.proj_id &&
        media_audio_response == A.media_audio_response &&
        media_cn == A.media_cn &&
        media_attr_cn == A.media_attr_cn &&
        media_name == A.media_name &&
        attri == A.attri &&
        pre_unit == A.pre_unit &&
        value == A.value &&
        value_cn == A.value_cn &&
        value_type == A.value_type &&
        unit == A.unit &&
        floor == A.floor &&
        area == A.area &&
        name_is_sure == A.name_is_sure &&
        is_scene == A.is_scene &&
        sentence == A.sentence
        );
}

ADDataType& ADDataType::operator =(const ADDataType &A){
    if(this == &A) return *this;
    Success = A.Success;
    media_id = A.media_id;
    proj_id = A.proj_id;

    media_audio_response = A.media_audio_response;
    media_cn = A.media_cn;
    media_attr_cn = A.media_attr_cn;
    media_name = A.media_name;
    attri = A.attri;
    pre_unit = A.pre_unit;
    value = A.value;
    value_cn = A.value_cn;
    value_type = A.value_type;
    unit = A.unit;

    m_through = A.m_through;
    m_range = A.m_range;

    floor = A.floor;
    area = A.area;
    name_is_sure = A.name_is_sure;
    is_scene = A.is_scene;
    sentence = A.sentence;

    return *this;
}

QList<ADDataType> ADDataType::Deseries(const QByteArray &bytes){
    QJsonParseError perr;
    QJsonDocument doc = QJsonDocument::fromJson(bytes, &perr);
    QList<ADDataType> result;
    if(perr.error != QJsonParseError::NoError) return result;
    QJsonArray array = doc.array();
    if(array.size() == 0) return result;
    for(int i=0; i<array.size(); i++){
        QJsonObject dict = array.at(i).toObject();
        result.push_back(ADDataType(dict));
    }
    return result;
}

void ADDataType::PrintOutInfo(){
    qDebug() << "Success = "<<Success;
    qDebug() << "media_id = "<<media_id;
    qDebug() << "proj_id = "<<proj_id;
    qDebug() << "media_audio_response = "<<media_audio_response;
    qDebug() << "media_cn ="<<media_cn;
    qDebug() << "media_attr_cn = "<<media_attr_cn;
    qDebug() << "media_name = "<<media_name;
    qDebug() << "attri = "<<attri;
    qDebug() << "pre_unit = "<<pre_unit;
    qDebug() << "value = "<<value;
    qDebug() << "value_cn = "<<value_cn;
    qDebug() << "value_type = "<<value_type;
    qDebug() << "unit = "<<unit;
    qDebug() << "floor = "<<floor;
    qDebug() << "area = "<<area;
    qDebug() << "name_is_sure = "<<name_is_sure;
    qDebug() << "is_scene = "<<is_scene;
    qDebug() << "sentence = "<<sentence;
    qDebug() << "trace = " << m_through;
    qDebug() << "range =" << m_range;

}
